// 1. 导入创建方法
import { createSlice } from "@reduxjs/toolkit";

// 2. 创建切片
const userSlice = createSlice({
    name: 'user',
    initialState: {
        // adminname: '',
        // checkedkeys: [],
        // role: 1,
        // token: '',
        // loginState: true
        userInfo: JSON.parse(localStorage.getItem('userInfo') == 'undefined' ? '{}' : localStorage.getItem('userInfo'))
    },
    reducers: {
        changeUserInfo(state, actions) {
            state.userInfo = actions.payload
            localStorage.setItem('userInfo', JSON.stringify(actions.payload))
        }
    }
})

export const { changeUserInfo } = userSlice.actions
export default userSlice.reducer